// pages/personalCenter/signUp/signUp.js
//在本页面用来临时保存用户注册数据
var userInfo = {};
var app = getApp();
Page({
    /**
     * 自定义函数
     */

    /**
     * 页面函数
     */

    //姓名输入
    name_input: function(e) {
        userInfo.user_name = e.detail.detail.value;
    },

    //组织选择框输入
    org_click: function(e) {
        this.setData({
            org_result: e.detail.value
        });
        //给部门赋值
        switch (e.detail.value) {
            case '指导老师':
                userInfo.user_id_org = '01';
                this.setData({
                    dep_content: ['指导老师']
                });
                break;
            case '西电官方微信':
                userInfo.user_id_org = '02';
                this.setData({
                    dep_content: ['负责人/总监', '采编部', '视觉部', '秘书部', '技术部']
                });
                break;
            case '西电官方微博':
                userInfo.user_id_org = '03';
                this.setData({
                    dep_content: ['负责人/总监', '微博组', '外联部']
                });
                break;
            case '西电官方哔哩哔哩':
                userInfo.user_id_org = '04';
                this.setData({
                    dep_content: ['负责人/总监', '日常组', '创意组']
                });
                break;
            case '西电小喇叭':
                userInfo.user_id_org = '05';
                this.setData({
                    dep_content: ['负责人/总监', '微信组', '微博组', '空间组']
                });
                break;
            case '714影像工作室':
                userInfo.user_id_org = '06';
                this.setData({
                    dep_content: ['负责人/总监', '摄影组', '外联部']
                });
                break;
            case '西电科大报':
                userInfo.user_id_org = '07';
                this.setData({
                    dep_content: ['负责人/总监', '采访部', '视觉部', '秘书部', '外联部']
                });
                break;
            case '雁塔晨钟':
                userInfo.user_id_org = '08';
                this.setData({
                    dep_content: ['负责人/总监', '秘书部']
                });
                break;
        }
        //显示部门
        this.setData({
            show_dep: true
        });
    },

    //部门选择框输入
    dep_click: function(e) {
        this.setData({
            dep_result: e.detail.value
        });
        //显示职位
        this.setData({
            show_position: true
        });
        switch (userInfo.user_id_org) {
            case '01':
                switch (e.detail.value) {
                    case '指导老师':
                        userInfo.user_id_depart = '01';
                        break;
                }
                break;
            case '02':
                switch (e.detail.value) {
                    case '负责人/总监':
                        userInfo.user_id_depart = '00';
                        break;
                    case '采编部':
                        userInfo.user_id_depart = '01';
                        break;
                    case '视觉部':
                        userInfo.user_id_depart = '02';
                        break;
                    case '秘书部':
                        userInfo.user_id_depart = '03';
                        break;
                    case '技术部':
                        userInfo.user_id_depart = '04';
                        break;
                }
                break;
            case '03':
                switch (e.detail.value) {
                    case '负责人/总监':
                        userInfo.user_id_depart = '00';
                        break;
                    case '微博组':
                        userInfo.user_id_depart = '01';
                        break;
                    case '外联部':
                        userInfo.user_id_depart = '02';
                        break;
                }
                break;
            case '04':
                switch (e.detail.value) {
                    case '负责人/总监':
                        userInfo.user_id_depart = '00';
                        break;
                    case '日常组':
                        userInfo.user_id_depart = '01';
                        break;
                    case '创意组':
                        userInfo.user_id_depart = '02';
                        break;
                }
                break;
            case '05':
                switch (e.detail.value) {
                    case '负责人/总监':
                        userInfo.user_id_depart = '00';
                        break;
                    case '微信组':
                        userInfo.user_id_depart = '01';
                        break;
                    case '微博组':
                        userInfo.user_id_depart = '02';
                        break;
                    case '空间组':
                        userInfo.user_id_depart = '03';
                        break;
                }
                break;
            case '06':
                switch (e.detail.value) {
                    case '负责人/总监':
                        userInfo.user_id_depart = '00';
                        break;
                    case '摄影组':
                        userInfo.user_id_depart = '01';
                        break;
                    case '外联部':
                        userInfo.user_id_depart = '02';
                        break;
                }
                break;
            case '07':
                switch (e.detail.value) {
                    case '负责人/总监':
                        userInfo.user_id_depart = '00';
                        break;
                    case '秘书部':
                        userInfo.user_id_depart = '03';
                        break;
                }
                break;
        }
    },

    //职位选择框输入
    position_click: function(e) {
        this.setData({
            position_result: e.detail.value
        });
        switch (e.detail.value) {
            case '指导老师':
                userInfo.user_rank = '1';
                break;
            case '组织负责人/总监/顾问':
                userInfo.user_rank = '2';
                break;
            case '各部门部长':
                userInfo.user_rank = '3';
                break;
            case '干事':
                userInfo.user_rank = '4';
                break;
        }
    },

    //提交表单
    submit: function() {
        if (userInfo.user_name == undefined) {
            wx.showModal({
                showCancel: false,
                title: '提示',
                content: '请填写姓名',
                confirmText: '我知道了'
            })
        } else {
            if (userInfo.user_id_org == undefined) {
                wx.showModal({
                    showCancel: false,
                    title: '提示',
                    content: '请选择组织',
                    confirmText: '我知道了'
                })
            } else {
                if (userInfo.user_id_depart == undefined) {
                    wx.showModal({
                        showCancel: false,
                        title: '提示',
                        content: '请选择部门',
                        confirmText: '我知道了'
                    })
                } else {
                    if (userInfo.user_rank == undefined) {
                        wx.showModal({
                            showCancel: false,
                            title: '提示',
                            content: '请选择职位',
                            confirmText: '我知道了'
                        })
                    } else {
                        //设置用户ID号
                        userInfo.user_id = userInfo.user_id_org + userInfo.user_id_depart + userInfo.user_id_person;
                        wx.request({
                            url: 'https://wx.jingqi.ink/wxapp/signup',
                            method: 'POST',
                            data: {
                                user_name: userInfo.user_name,
                                user_id: userInfo.user_id,
                                user_openid: app.globalData.user_info.user_openid,
                                user_rank: userInfo.user_rank
                            },
                            success: function(res) {
                                wx.showModal({
                                    showCancel: false,
                                    title: '提示',
                                    content: '您的申请已提交，请等待管理员审核通过',
                                    confirmText: '我知道了',
                                    success: function() {
                                        wx.navigateBack({
                                            url: '../../index/index'
                                        })
                                    }
                                })
                            }
                        })
                    }
                }
            }
        }
    },

    reset: function() {
        var that = this;
        wx.showModal({
            title: '提示',
            content: '确认重置？',
            confirmText: '确认',
            confirmColor: '#ff0000',
            cancelText: '返回',
            success(res) {
                if (res.confirm) {
                    that.setData({
                        name_value: ''
                    });
                    that.setData({
                        org_result: ''
                    });
                    that.setData({
                        dep_result: ''
                    });
                    that.setData({
                        position_result: ''
                    });
                    that.setData({
                        show_dep: false
                    });
                    that.setData({
                        show_position: false
                    });
                }
            }
        })
    },

    /**
     * 页面的初始数据
     */
    data: {
        //不显示部门和职位
        show_dep: false,
        show_position: false,
        //职位
        position_content: [
            "指导老师",
            "组织负责人/总监/顾问",
            "各部门部长",
            "干事"
        ],
        show: false,
        org_content: [
            "指导老师",
            "西电官方微信",
            "西电官方微博",
            "西电官方哔哩哔哩",
            "西电小喇叭",
            "714影像工作室",
            "西电科大报",
            "雁塔晨钟"
        ],
        orgChoose: 0,
        departChoose: 0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function() {
        //在注册页面加载完成后以当前时间的毫秒数为用户分配一个user_id_person
        userInfo.user_id_person = Date.now();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        wx.hideShareMenu({});
        wx.setNavigationBarTitle({
            title: '用户注册',
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})